/*     */ package com.newcrm.businessarchives;
/*     */ 
/*     */ import com.newcrm.util.Util;
/*     */ import java.io.IOException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Connection.Method;
/*     */ import org.jsoup.Connection.Response;
/*     */ import org.jsoup.Jsoup;
/*     */ import org.jsoup.nodes.Document;
/*     */ import org.jsoup.nodes.Element;
/*     */ import org.jsoup.select.Elements;
/*     */ 
/*     */ public class ShanghaiSearchEngine extends SearchEngine
/*     */ {
/*  23 */   private static Logger logger = Logger.getLogger(ShanghaiSearchEngine.class
/*  24 */     .getName());
/*     */   private static final String SUB_URL = "http://www.sgs.gov.cn/lz/etpsInfo.do?method=viewDetail";
/*  28 */   private Map<String, String> params = new HashMap();
/*     */ 
/*     */   public ShanghaiSearchEngine(String name) {
/*  31 */     this.name = standardizedName(name);
/*  32 */     this.params.put("名称:", "CompanyName");
/*  33 */     this.params.put("注册号:", "SN");
/*  34 */     this.params.put("法定代表人姓名:", "Header");
/*  35 */     this.params.put("住所:", "Address");
/*  36 */     this.params.put("注册资本:", "RegisteredCapital");
/*  37 */     this.params.put("公司类型:", "CompanyType");
/*  38 */     this.params.put("成立日期:", "FoundedDate");
/*  39 */     this.params.put("营业期限:", "OperatingPeriod");
/*  40 */     this.params.put("登记机关:", "RegistrationAuthority");
/*  41 */     this.params.put("企业状态:", "AnnualinSpectionResult");
/*  42 */     this.params.put("经营范围:", "BusinessScope");
/*     */   }
/*     */ 
/*     */   protected Map<String, Object> getCompanyByWeb()
/*     */   {
/*     */     try
/*     */     {
/*  49 */       Connection.Response res = Jsoup.connect("http://www.sgs.gov.cn/lz/etpsInfo.do?method=doSearch")
/*  50 */         .data(new String[] { 
/*  50 */         "keyWords", this.name, "searchType", "1" })
/*  51 */         .method(Connection.Method.POST).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000)
/*  52 */         .execute();
/*     */ 
/*  54 */       Document doc = res.parse();
/*     */ 
/*  56 */       Elements links = doc.select("table[class=con] tr td a");
/*  57 */       List detailsUrl = new ArrayList();
/*  58 */       for (Element item : links) {
/*  59 */         detailsUrl.add(item.attr("onclick"));
/*     */       }
/*     */ 
/*  62 */       if (detailsUrl.size() == 0) {
/*  63 */         return null;
/*     */       }
/*  65 */       String tmp = (String)detailsUrl.get(0);
/*  66 */       String id = tmp.substring(12, tmp.length() - 2);
/*  67 */       Map cookies = res.cookies();
/*  68 */       Connection connection2 = Jsoup.connect("http://www.sgs.gov.cn/lz/etpsInfo.do?method=viewDetail");
/*  69 */       for (Object cookieO : cookies.entrySet()) {
            Map.Entry cookie = (Map.Entry) cookieO;
/*  70 */         connection2.cookie((String)cookie.getKey(), (String)cookie.getValue());
/*     */       }
/*     */ 
/*  73 */       Connection.Response detailRes = connection2
/*  74 */         .referrer(
/*  75 */         "http://www.sgs.gov.cn/lz/etpsInfo.do?method=doSearch")
/*  76 */         .data("etpsId", id).method(Connection.Method.POST)
/*  77 */         .userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000).execute();
/*     */ 
/*  79 */       doc = detailRes.parse();
/*  80 */       links = doc
/*  81 */         .select("table[class=list_boder] td[class=list_title_boeder]");
/*     */ 
/*  83 */       Object info = new HashMap();
/*  84 */       for (Element item : links) {
/*  85 */         String key = item.text().trim();
/*  86 */         if (this.params.containsKey(key))
/*     */         {
/*  90 */           ((Map)info).put((String)this.params.get(key), item.nextElementSibling().html()
/*  91 */             .replace("&nbsp;", ""));
/*     */         }
/*     */       }
/*  93 */       ((Map)info).put("UpdateDate", Util.date2Str(new Date()));
/*  94 */       if (((Map)info).size() > 1) {
/*  95 */         super.saveDB((Map)info);
/*     */       }
/*  97 */       return (Map)info;
/*     */     } catch (IOException e) {
/*  99 */       logger.warn("get shanghai company info failed", e);
/*     */     }
/* 101 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.businessarchives.ShanghaiSearchEngine
 * JD-Core Version:    0.6.1
 */